package com.hup.sokoban.model.common;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

import java.util.ArrayList;

/**
 * 移动操作的记录类
 * @author hugan
 * @date 2020/5/11
 */
@ToString
public class StepRecord {

    @Getter
    private ArrayList<CellInfo> cells = new ArrayList<>();

    public void add(CellInfo step) {
        cells.add(step);
    }

    /**
     * 单个格子,移动前后的信息
     */
    @ToString
    @EqualsAndHashCode
    public static class CellInfo {
        /**
         * 格子index
         */
        @JSONField(ordinal = 1)
        public final int index;
        /**
         * 移动后的值
         */
        @JSONField(ordinal = 2)
        public final int valueBefore;
        /**
         * 移动前的值
         */
        @JSONField(ordinal = 3)
        public int valueAfter;

        public CellInfo(int index, int valueBefore) {
            this.index = index;
            this.valueBefore = valueBefore;
        }

        /**
         * for json反序列化
         */
        public CellInfo(int index, int valueBefore, int valueAfter) {
            this.index = index;
            this.valueBefore = valueBefore;
            this.valueAfter = valueAfter;
        }
    }

}
